package schoolsys.controller;



import schoolsys.service.StudentService;
import schoolsys.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "DeleteStuByNoServlet", value = "/DeleteStuByNoServlet")
public class DeleteStuByNoServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //先处理中文乱码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        //设置请求内容类型编码
        response.setContentType("text/html;utf-8");
        String studentNo=request.getParameter("stuNo");
        long stuNo = 0;
        if (studentNo!=null&&!"".equals(studentNo)){
            stuNo=Long.parseLong(studentNo);
        }
        //调用删除方法
        StudentService studentService = new StudentServiceImpl();
        int n = studentService.deleteStuByNo(stuNo);
        System.out.println("1");
        response.sendRedirect("/SelectStuListServlet?action=delete&n="+n);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
